var arr = []
var input = document.getElementsByClassName('input')
var cuo = document.getElementsByClassName('cuo')
var b = /^1[3456789]\d{9}$/;
// 手机号正则
var yes = document.getElementById('yes')
var no = document.getElementById('no')
var cg = document.getElementsByClassName('cg')[0]
var tim;
function ti(){
var isValid = true; 
    if(input[0].value ==''){
        cuo[0].innerHTML='<span>请输入姓名</span>'
        isValid = false
    }else{
        cuo[0].innerHTML=''
    }
    if(input[1].value == ''){
        cuo[1].innerHTML='<span>请输入村镇</span>'
        isValid = false
    }else{
        cuo[1].innerHTML=''
    }
    if(b.test(input[2].value)){
        cuo[2].innerHTML=''
    }else{
        cuo[2].innerHTML='<span>请输入正确的手机号</span>'
        isValid = false
    }
    if(yes.checked || no.checked){
        cuo[3].innerHTML=''
        if(yes.checked){
            yn = true
        }else{
            yn = false
        }
    }else{
        cuo[3].innerHTML='<span>请选择选项</span>'
        isValid = false
    }
    if (isValid) {
        tim = setInterval(function(){
            cg.style.display='block'
        },500)
        for(var i=0;i<input.length;i++){
            input[i].value=''
        }
        }
        yes.checked = false;
        no.checked = false;
        xhr({
            methods:'post',
            url:'visitors',
            data:JSON.stringify({
                name: input[0].value.trim(),
                location: input[1].value.trim(),
                phone: input[2].value.trim(),
                canAcceptCall: yn,
            }),
            success:function(az){
                console.log(az)
            }
        })
    }
    function guan(){
        cg.style.display='none'
        clearInterval(tim)
    }